package com.jfinal.ext.plugin.mail;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author Timor
 * @version 1.0
 * @date 2022/10/14 17:45:53
 */
public class MailKit {
    private static final Map<String, IMailService> SERVICES = new ConcurrentHashMap<>();

    public static IMailService use() {
        return use(MailPlugin.MAIN_CONFIG);
    }

    public static IMailService use(String configName) {
        return SERVICES.get(configName);
    }

    static void add(String configName, IMailService service) {
        if (SERVICES.containsKey(configName)) {
            throw new RuntimeException(configName + "配置的Mail已经存在！");
        } else {
            SERVICES.put(configName, service);
        }
    }
}
